/**
 * <p>文件名:		AnnotationTestBean.java</p>
 * <p>版权:		CopyrightTag</p>
 * <p>公司:		CompanyTag</p>
 * @author		周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
 */

package com.caits.lbs.framework.services.jmx;

/**
 * <p>
 * AnnotationTestBean
 * </p>
 * <p>
 * 利用Spring的注解方便的实现jmx管理
 * </p>
 * 
 * @author 周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
 * @version 0.0.0
 *          <table style="border:1px solid gray;">
 *          <tr>
 *          <th width="100px">版本号</th>
 *          <th width="100px">动作</th>
 *          <th width="100px">修改人</th>
 *          <th width="100px">修改时间</th>
 *          </tr>
 *          <!-- 以 Table 方式书写修改历史 -->
 *          <tr>
 *          <td>0.0.0</td>
 *          <td>创建类</td>
 *          <td>zhb</td>
 *          <td>2010-12-10 下午05:10:41</td>
 *          </tr>
 *          <tr>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          <td>XXX</td>
 *          </tr>
 *          </table>
 */
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;

import com.caits.lbs.framework.log.CommonLogFactory;

// 实例标记为由JMX管理的资源
@ManagedResource(objectName = "bean:name=logLevelJmx", description = "My Managed Bean", log = true, logFile = "jmx.log", currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200, persistLocation = "foo", persistName = "bar")
public class LogLevelAnnotation {

	

	/** 日志类 */
	private static Logger log = CommonLogFactory.getLog();
	
	/**
	 * 设置日志级别
	 * @param level
	 */
	private void setLevel(Level level){
		
		log.setLevel(level);
	}
	
	/**
	 * 设置为debug
	 */
	@ManagedOperation(description = "setDebug")
	@ManagedOperationParameters({
			})
	public void setDebug(){
		Level level=Level.DEBUG;
		setLevel(level);
	}
	/**
	 * 设置为setInfo
	 */
	@ManagedOperation(description = "setInfo")
	@ManagedOperationParameters({
			})
	public void setInfo(){
		Level level=Level.INFO;
		setLevel(level);
	}
	/**
	 * 设置为setWarn
	 */
	@ManagedOperation(description = "setWarn")
	@ManagedOperationParameters({
			})
	public void setWarn(){
		Level level=Level.WARN;
		setLevel(level);
	}
	

	/**
	 * 设置为setError
	 */
	@ManagedOperation(description = "setError")
	@ManagedOperationParameters({
			})
	public void setError(){
		Level level=Level.ERROR;
		setLevel(level);
	}
	/**
	 * 设置为setFatal
	 */
	@ManagedOperation(description = "setFatal")
	@ManagedOperationParameters({
			})
	public void setFatal(){
		Level level=Level.FATAL;
		setLevel(level);
	}
	/**
	 * 设置为setTrace
	 */
	@ManagedOperation(description = "setTrace")
	@ManagedOperationParameters({
			})
	public void setTrace(){
		Level level=Level.TRACE;
		setLevel(level);
	}
	/**
	 * 设置为setOff
	 */
	@ManagedOperation(description = "setOff")
	@ManagedOperationParameters({
			})
	public void setOff(){
		Level level=Level.OFF;
		setLevel(level);
	}
	// 把方法标记为JMX的操作
	@ManagedOperation(description = "Add two numbers")
	@ManagedOperationParameters({
			@ManagedOperationParameter(name = "x", description = "The first number"),
			@ManagedOperationParameter(name = "y", description = "The second number")})
	public int add(int x, int y) {
		return x + y;
	}

	public void dontExposeMe() {
		throw new RuntimeException();

	}

	
}
